//
//  ScrollViewController.m
//  UIScrollView
//
//  Created by Sang-don Lee on 11. 11. 9..
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "ScrollViewController.h"
#import "TipToolBar.h"

@implementation ScrollViewController

#pragma mark - Life Cycle

- (void)viewDidLoad
{
    scrollView = [[UIScrollView alloc] initWithFrame:[self frameForScrollView]];
    scrollView.pagingEnabled = YES;
    scrollView.backgroundColor = [UIColor blackColor];
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.delegate = self;
    
    
    for (int i = 1; i < 6; i++)
    {
        NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        
        CGRect frame = CGRectZero;
        frame.size.width = scrollView.frame.size.width;
        frame.size.height = scrollView.frame.size.height;
        frame.origin.x = ((scrollView.frame.size.width - frame.size.width) / 2) + ((i - 1) * scrollView.frame.size.width);
        frame.origin.y = (scrollView.frame.size.height - frame.size.height) / 2;
        
        imageView.frame = frame;
        
        [scrollView addSubview:imageView];
        [imageView release];
    }
    
    scrollView.contentSize = CGSizeMake(scrollView.subviews.count * scrollView.frame.size.width, scrollView.frame.size.height);
    
    [self.view addSubview:scrollView];
    
    tipToolBar = [[TipToolBar alloc] init];
    [self.view addSubview:tipToolBar];
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    scrollView = nil;
    [super viewDidUnload];
}

- (void)dealloc
{
    [scrollView release];
    [super dealloc];
}

#pragma mark - Methods

- (CGRect)frameForScrollView
{
    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.x -= 10;
    frame.size.width += 20;
    
    return frame;
}

@end
